package com.dianjing.dianqun.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dianjing.dianqun.common.base.BaseRestController;
import com.dianjing.dianqun.model.Content;
import com.dianjing.dianqun.model.DianPaiContent;
import com.dianjing.dianqun.model.Site;
import com.dianjing.dianqun.service.ContentService;
import com.dianjing.dianqun.service.SiteService;
import com.dianjing.dianqun.service.UserService;
import com.dianjing.dianqun.service.dianpai.DianPaiContentService;

/**
 * @date : 2017年11月23日
 * 
 *       分享专用 无任何认证身份
 * 
 * @author: baoyongtao
 * 
 * @see :
 * 
 */
@Controller
@RequestMapping("/share")
public class ShareController extends BaseRestController {

	@Autowired
	private ContentService contentService;

	@Autowired
	private DianPaiContentService dianPaiContentService;

	@Autowired
	private UserService userService;

	@Autowired
	private SiteService siteService;

	@GetMapping("/team")
	public String team(Integer contentId, ModelMap model) {
		Content content = contentService.selectByPrimaryKey(contentId);
		model.addAttribute("content", content);
		return "share/team";
	}

	@GetMapping("/about")
	public String about(Integer contentId, ModelMap model) {
		Content content = contentService.selectByPrimaryKey(contentId);
		if (content != null) {
			Site site = siteService.selectSitelByUserId(content.getUserId());
			model.addAttribute("user", userService.selectByPrimaryKey(content.getUserId()));
			model.addAttribute("site", site);
		}
		model.addAttribute("content", content);
		return "share/about";
	}

	@GetMapping("/dianpai")
	public String dianpai(Integer contentId, ModelMap model) {
		 DianPaiContent dianPaiContent = dianPaiContentService.selectByPrimaryKey(contentId);
		if (dianPaiContent != null) {
			model.addAttribute("user", userService.selectByPrimaryKey(dianPaiContent.getUserId()));
		}
		model.addAttribute("content", dianPaiContent);
		return "share/dianpai";
	}

	@GetMapping("/content")
	public String content(Integer contentId, ModelMap model) {
		Content content = contentService.selectByPrimaryKey(contentId);
		if (content != null) {
			model.addAttribute("user", userService.selectByPrimaryKey(content.getUserId()));
		}
		model.addAttribute("content", content);
		return "share/content";
	}
}
